//可以不写<string>，因为包含在<iostream>
/* #include <string> */
#include <iostream>
using std::cout;
using std::endl;
using std::string;

void test0(){
    //string首字母不要大写
    //无参构造
    string str;
    cout << "str:" << str << endl;
    //如果是空字符串，返回1，否则返回0
    cout << str.empty() << endl;

    //创建由多个相同字符构成的字符串
    string str2(5,'a');
    cout << "str2:" << str2 << endl;
    cout << str2.empty() << endl;
    //返回字符数
    cout << str2.size() << endl;
    cout << str2.length() << endl;
    str2.push_back('b');
    cout << str2 << endl;

    //拷贝构造，复制一个basic_string类对象
    string str3(str2);
    cout << "str3:" << str3 << endl;

    //复制一个C风格字符串
    string str4("hello");
    cout << "str4:" << str4 << endl;
    /* str4.append(5,'x'); */
    /* cout << str4 << endl; */


    //从头开始将一个C风格字符串复制count个字符
    string str5("hello",2);
    cout << "str5:" << str5 << endl;
    str5.append(str4,2,3);
    cout << str5 << endl;

    str5.append(",world");
    cout << str5 << endl;
    printf("%s\n",str5.c_str());
    /* str5.append(str2); */
    /* cout << str5 << endl; */


    //从pos位开始复制一个string
    string str6(str4,2);
    cout << "str6:" << str6 << endl;

    int pos = str5.find(str4);
    cout << "pos:" << pos << endl;

    pos = str5.find(str6);
    cout << "pos:" << pos << endl;

    //C++风格字符串进行比较
    string str7("yes");
    string str8("yess");
    //字符串内容相同就返回1,不同就返回0
    cout << (str7 == str8) << endl;

}

int main(void){
    test0();
    return 0;
}
